call function between classes [closed]

Posted by aziz joh on Programmers See other posts from Programmers or by aziz joh
Published on 2011-02-21T03:43:47Z Indexed on 2011/02/21 7:32 UTC
Read the original article Hit count: 338

Filed under:
|
|
|

hello I have 3 classes class A, B, and C

class A is the main class and content the main function also, i call class B and class C in the main as b1,b2 and c1.

in class B there is a vector (V) has list of int. and 3 functions Add, get and delete delete. all the thing in the class is public.

in class C i have function that need to (B::get) from b.

what I want is that how I can make c1 call get of b1 to return the value of the V in b1 after that use add of b2 to add new item in V of b2. Thanks in advance

This is an example

class a{
    int main(){
        b b1,b2;
        c c1;
        b1.add(10);
        b1.add(20);
        c1.start();
    }}

class b{
    vector<int> v;
    void add(int i){
        v.push_back(i)}
    int get(){int i=v.at(0); return i;}
    }

class c{// take something from b1 and add it to b2
    void play(){
        int i=b.get();//should take it from b1
        b.add(i*2);//should add it to b2
    }}

please I need your help I been searching to solve this problem for days.

© Programmers or respective owner

Related posts about c++

Related posts about oop